
var App;
if (!App)
    App = {};

App.showCashState = function (value, row, index) {
    if (value == 0) return '<span >否</span>';
    if (value == 1) return '<span style="color:red">是</span>';
}

App.show = function (value, row, index) {
    if (value==1||value==3||value==5) return '<span >ios</span>';
    if (value==2||value==4||value==6) return '<span >android</span>';
}


var shiyongduan = function(value, row, index){
    if(value==1||value==2){
        return "用户端";
    }
    if(value==3||value==4){
        return "配送端";
    }
    if(value==5||value==6){
        return "商家端";
    }
}

// App.showTag = function (value, row, index) {
//     if (value == '1') return '<span >用户端</span>';
//     if (value == '2') return '<span >商家端</span>';
//     if(value=='3') return '<span>配送端</span>';
// }


//升级保存右侧页面数据
bindClick("button[data-event=submit-saveapp]", function (tag) {
    var form = $("#appform");
    var v = form.valid();
    if (v == false) {
        return false;
    }

    var params = form.formToArray();
    comment.post(form.attr("action"), params, '执行保存', function (res) {
        if (res.res.code == 40000) {
            //关闭model方法
            closeModel("upapp-div");
            var table = $("#table");
            table.bootstrapTable("refresh");
        }else{
            hint(res.res.msg);
        }
    });
});

//操作格式函数
operateFormatter = function (value, row, index) {
    //     '<a class="show1" href="javascript:void(0)">查看</a>&nbsp;&nbsp;'+'<a class="edit" href="javascript:void(0)">编辑</a>&nbsp;&nbsp;'+'<a class="delete" href="javascript:void(0)">删除</a>'
    // ].join('');

       return  ['<a class="show1" href="javascript:void(0)">查看</a>&nbsp;&nbsp;'+'<a class="edit" href="javascript:void(0)">升级</a>&nbsp;&nbsp;'].join('');
}

//操作按鈕动作
window.operateEvents = {
    'click .show1': function (e, value, row, index) {
        showModel("show-div", function () {

            var div = $("#show-div");

            var devPlatform="";
            var shiyongduan="";

            if(row.devPlatform==1||row.devPlatform==3||row.devPlatform==5){
                devPlatform='ios';
            }else if(row.devPlatform==2||row.devPlatform==4||row.devPlatform==6){
                devPlatform='android';
            }

            if(row.devPlatform==1||row.devPlatform==2){
                shiyongduan='用户端';
            }
            if(row.devPlatform==3||row.devPlatform==4){
                shiyongduan="配送端";
            }
            if(row.devPlatform==5||row.devPlatform==6){
                shiyongduan="商家端";
            }

            var isFource =row.isForce;



            $("#show-div input:radio[value="+isFource+"]").prop('checked',true);

            div.find("input[name=shiyongduan]").val(shiyongduan);
            div.find("input[name=devPlatform]").val(devPlatform);
            div.find("input[name=tagVersion]").val(row.tagVersion);
            div.find("input[name=version]").val(row.version);
            div.find("input[name=url]").val(row.url);
            div.find("input[name=updated]").val(row.updated);
            div.find("input[name=id]").val(row.id);
            div.find("textarea[name=updateInfo]").val(row.updateInfo);
        });
    },

    'click .edit':function(e, value, row, index){
        showModel("editapp-div", function () {
            $.each($("#editappform input"), function () {
                var value = $(this).val();
                $(this).val(value).css("color", "#000");
            });

            $.each($("#editappform label[class=error]"),function(){
                $(this).remove();
            });
            var div = $("#editapp-div")

            var isFource =row.isForce;

            $("#editapp-div input:radio[value="+isFource+"]").prop('checked',true);

            div.find("input[name=tagversion]").val(row.tagVersion);
            div.find("input[name=version]").val(row.version);
            div.find("input[name=url]").val(row.url);
            div.find("textarea[name=updateInfo]").val(row.updateInfo);

            div.find("input[type=hidden]").val(row.id);
        });
    },
    'click .delete':function(e, value, row, index){
        comment.showOperationTips("确定删除吗？", function () {
            $.post($().AbsUrlParse('/web/app/delete'), {
                id: row.id
            }, function (data) {
                if (data.state == true) {
                    if (data.res.code == 40000) {
                        hint("删除成功");
                        var table = $("#table");
                        table.bootstrapTable("refresh");
                    } else {
                        hint(data.res.msg);
                    }
                } else {
                    hint(data.msg);
                }
            });
        });
    }
};

bindClick("#editappsave",function(){

    var form = $("#editappform");
    var v =form.valid();
    if(v==false){
        return false;
    }

    var param = form.formToArray();
    $.post(form.attr("action"), param, function (res) {
        if (res.state && res.res.code == 40000) {
            hint('修改成功！');
            closeModel('editapp-div');
            var table = $("#table");
            table.bootstrapTable("refresh");
        } else {
            if (res.state == false) {
                hint(res.msg);
            } else {
                hint(res.res.msg);
            }
        }
    });


})



